<!DOCTYPE html>
<html>
<head>

<link rel="stylesheet" type="text/css" href="../CssFrame/bootstrap-theme.css">
<link rel="stylesheet" type="text/css" href="../CssFrame/bootstrap.css">

<script src="../Jquery/Jquery-3.3.1.js" type="text/javascript"></script>

<script src="../Jquery/jquery.table2excel.js" type="text/javascript"></script>

<script src="../MySelfJS/CheckFunction.js" type="text/javascript"></script>

<meta charset="UTF-8">
<title>历史访客名单</title>

<style type="text/css">
th {
	text-align: center;
}
</style>

</head>
<body>
	<div style="text-align: center;">
		<h4 style="margin-top: 35px;">访客登记表</h4>
		<div>
			<input type="button" value="导出为excel" class="btn btn-primary" onclick="table2Excel('访客登记表.xls')" />
			<table cellspacing="0" cellpadding="0" border="1" width="90%" id="mine_table" class="table2excel"
				style="margin-left: 50px; margin-top: 2%;">
				<th>序号</th>
				<th>访客证件号</th>
				<th>访客姓名</th>
				<th>所访学生姓名</th>
				<th>所访学生楼号</th>
				<th>所访学生寝室号</th>
				<th>访客身份</th>
				<th>到访时间</th>
				<th>离去时间</th>
				<th class="noExl">删除</th>
				<th class="noExl">修改</th>

				<tbody id="visitory_table_body">

				</tbody>
			</table>
		</div>

		<div style="margin-top: 30px;">
			<a href="DormitoryManageSystem.html">返回系统导航页</a>
		</div>

	</div>
</body>

<script type="text/javascript">
	$(document).ready(function() {
		showVisitorsList();
	});

	/**
	 * 住宿生列表展示
	 */
	function showVisitorsList() {
		var url = "/dormitory/Visit/exhibi_visitor";
		$.ajax({
			url : url,
			type : "GET",
			contentType : "application/json;cherset=utf-8",
			dataType : "json",
			success : function(j) {
				if (j.state == 200) {
					$("#visitory_table_body").empty();

					var list = j.data;

					var n = 1;

					if (list !== null) {
						//对list值进行遍历
						for (var index = 0; index <= list.length; index++) {
							var child = '<tr> <td>' + n++ + ' </td>'
									+ '<td class="visitorCardno_item">#{visitorCardno}</td> '
									+ '<td class="visitorName_item">#{visitorName}</td> '
									+ '<td class="visitedStudentName_item">#{visitedStudentName}</td> '
									+ '<td class="visitedStudentBuilding_item">#{visitedStudentBuilding}</td> '
									+ '<td class="visitedStudentChamber_item">#{visitedStudentChamber}</td> '
									+ '<td class="relation_item">#{relation}</td> '
									+ '<td class="visitorTime_item">#{visitorTime}</td> '
									+ '<td class="leaveTime_item">#{leaveTime}</td> '
									+ '<td class="noExl"><a href="javascript:deleByVid(#{vid})">删除</a></td> '
									+ '<td class="noExl"><a href="javascript:editByVid(#{vid})">修改</a></td>' + '</tr>';

							/*  */
							child = child.replace(/#{visitorCardno}/g, list[index].visitorCardno);
							child = child.replace(/#{visitorName}/g, list[index].visitorName);
							child = child.replace(/#{visitedStudentName}/g, list[index].visitedStudentName);
							child = child.replace(/#{visitedStudentBuilding}/g, list[index].visitedStudentBuilding);
							child = child.replace(/#{visitedStudentChamber}/g, list[index].visitedStudentChamber);
							child = child.replace(/#{visitorTime}/g, list[index].visitorTime);
							child = child.replace(/#{leaveTime}/g, list[index].leaveTime);
							child = child.replace(/#{vid}/g, list[index].vid);

							/* 访客身份 */
							switch (list[index].relation) {
							case 0:
								child = child.replace(/#{relation}/g, '家人');
								break;

							case 1:
								child = child.replace(/#{relation}/g, '朋友');
								break;

							case 2:
								child = child.replace(/#{relation}/g, '同学');
								break;

							case 3:
								child = child.replace(/#{relation}/g, '老师');
								break;

							case 4:
								child = child.replace(/#{relation}/g, '外卖快递');
								break;

							default:
								child = child.replace(/#{relation}/g, '其他');
								break;
							}

							//将信息追加
							$("#visitory_table_body").append(child);
						}

					}
				}
			}
		});
	}

	/**
	 * 删除student
	 */
	function deleByVid(vid) {
		var url = '/dormitory/Visit/del_visitor';
		$.ajax({
			url : url,
			type : "POST",
			data : {
				'vid' : vid
			},
			dataType : "json",
			success : function(j) {
				if (j.state == 200) {
					alert('删除成功')
					location.reload()
				} else {
					alert(j.message)
				}
			}
		});
	}

	/**
	 * 将要修改的数据发送给后台
	 */
	function editByVid(vid) {
		var url = '/dormitory/Visit/show_edit_vi';
		$.ajax({
			url : url,
			type : "POST",
			data : {
				'vid' : vid
			},
			dataType : "json",
			success : function(j) {
				if (j.state == 200) {
					location.href = "ExecuteEditVi.html";
				} else {
					alert(j.message)
				}
			}
		});
	}

	/*  */
	//fileName 导出的excel文件名
	//方法可带fileName参数，亦可不带参数直接定义
	function table2Excel(fileName) {
		$(".table2excel").table2excel({
			exclude : ".noExl",//排除.noExl,即class="noExl"的列不导出
			name : "Excel Document Name",
			filename : fileName,//文件名称
			fileext : ".xls",//文件后缀名
			exclude_img : true,//导出图片
			exclude_links : true,//导出超链接
			//导出输入框内容
			exclude_inputs : true
		});
	}
</script>

</html>